package com.lvy.hczn.front.business.controller;

import java.util.List;

import com.lvy.hczn.front.system.domain.business.PackSpu;
import com.lvy.hczn.front.system.service.PackSpuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * 商品关联的包装袋Controller
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@Controller
@RequestMapping("/system/spu")
public class PackSpuController extends BaseController {
    private String prefix = "system/pack/spu";

    @Autowired
    private PackSpuService packSpuService;

    @RequiresPermissions("system:pack:spu:view")
    @GetMapping()
    public String spu() {
        return prefix + "/spu";
    }

    /**
     * 查询商品关联的包装袋列表
     */
    @RequiresPermissions("system:pack:spu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PackSpu packSpu) {
        startPage();
        List<PackSpu> list = packSpuService.selectPackSpuList(packSpu);
        return getDataTable(list);
    }

    /**
     * 导出商品关联的包装袋列表
     */
    @RequiresPermissions("system:pack:spu:export")
    @Log(title = "商品关联的包装袋", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PackSpu packSpu) {
        List<PackSpu> list = packSpuService.selectPackSpuList(packSpu);
        ExcelUtil<PackSpu> util = new ExcelUtil<PackSpu>(PackSpu.class);
        return util.exportExcel(list, "商品关联的包装袋数据");
    }

    /**
     * 新增商品关联的包装袋
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存商品关联的包装袋
     */
    @RequiresPermissions("system:pack:spu:add")
    @Log(title = "商品关联的包装袋", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PackSpu packSpu) {
        return toAjax(packSpuService.insertPackSpu(packSpu));
    }

    /**
     * 修改商品关联的包装袋
     */
    @RequiresPermissions("system:pack:spu:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        PackSpu packSpu = packSpuService.selectPackSpuById(id);
        mmap.put("packSpu", packSpu);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品关联的包装袋
     */
    @RequiresPermissions("system:pack:spu:edit")
    @Log(title = "商品关联的包装袋", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PackSpu packSpu) {
        return toAjax(packSpuService.updatePackSpu(packSpu));
    }

    /**
     * 删除商品关联的包装袋
     */
    @RequiresPermissions("system:pack:spu:remove")
    @Log(title = "商品关联的包装袋", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(packSpuService.deletePackSpuByIds(ids));
    }
}
